package hu.kisprof.quiz.view;

import hu.kisprof.quiz.controller.QuizController;
import hu.kisprof.quiz.view.panels.QuizGamePanel;
import hu.kisprof.quiz.view.panels.QuizLoginPanel;

import java.awt.Container;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;


public class QuizGUI {
	private JFrame window;
	private QuizController control;
	private QuizGamePanel gp;
	

	public QuizGUI(QuizController quizController) {
		control = quizController;
	}

	public void startGUI(){
		javax.swing.SwingUtilities.invokeLater(new Runnable(){
			public void run(){
				createAndShowGUI();
			}
		});
	}
	
	public void createAndShowGUI() {
		window = new JFrame ("Quiz 2011");
		window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		
		/*QuizMenuBar menubar = new QuizMenuBar(this,QuizMenuBar.NOUSER);
		
		window.setJMenuBar(menubar);*/
		window.setMaximumSize(new Dimension(520,551));
		window.setMinimumSize(new Dimension(515,550));
		//window.setPreferredSize(new Dimension(515,550));
		window.setVisible(true);
		setActualContent(new QuizLoginPanel(this));
	
	}
	
	public void setActualContent(Container c){
		if(!(c instanceof QuizGamePanel)){
			gp=null;
		}
		window.setContentPane(c);
		window.setVisible(true);
	}
	
	public void updateContentData(){
		((ActionListener) window.getContentPane()).actionPerformed(new ActionEvent(window.getContentPane(),ActionEvent.ACTION_PERFORMED,"update"));
	}
	
	
	
	public void showGamePanel(){
		gp = new QuizGamePanel(this);
		setActualContent(gp);
	}
	
	public QuizController getControl() {
		return control;
	}

	public JFrame getWindow() {
		return window;
	}

	public QuizGamePanel getGp() {
		return gp;
	}

}
